package com.lib.Serialize;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class objectSerializeUtil {
	private static final long serialVersionUID = 7L;
	public static void serialize(Object object,String fileName) throws IOException
	{
		 File f = new File(fileName);
	    // filePath = f.getAbsolutePath();
	     if(!f.exists())
	     {
	    	 f.createNewFile();
	     }
		FileOutputStream outputStream=new FileOutputStream(fileName);
		ObjectOutputStream oos=new ObjectOutputStream(outputStream);
		oos.writeObject(object);
		outputStream.close();
	}
	public static Object deserialize(String fileName) throws IOException
	{
		Object object=new Object();
		File file=new File(fileName);
		if(!file.exists())
		{
			return null;
		}
		FileInputStream inputStream=new FileInputStream(file);
		ObjectInputStream ois=new ObjectInputStream(inputStream);
		try {
			object=ois.readObject();
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		inputStream.close();
		return object;
	}

}
